package cn.cslg.weatherforecast;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class DailyAdapter extends RecyclerView.Adapter<DailyAdapter.ViewHolder> {
    private List<DailyBean> dailyList;

    public DailyAdapter(List<DailyBean> dailyList) {
        this.dailyList = dailyList;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView textView;
        TextView textView2;
        TextView textView3;

        public ViewHolder(View view) {
            super(view);
            imageView = view.findViewById(R.id.imageView);
            textView = view.findViewById(R.id.textView);
            textView2 = view.findViewById(R.id.textView2);
            textView3 = view.findViewById(R.id.textView3);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.daily_item_layout, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        DailyBean dailyBean = dailyList.get(position);
//        holder.imageView.setImageResource(dailyBean.getImageId());
        String[] temp = dailyBean.getDate$day_weather$night_templow$day_temphigh().split("\\$");
        String tq=temp[1];
        if (tq!=null&&!tq.equals("")){
            if (tq.contains("多云"))
                holder.imageView.setImageResource(R.drawable.duoyun);
            else if (tq.contains("雨"))
                holder.imageView.setImageResource(R.drawable.zhenyu);
            else if (tq.contains("晴"))
                holder.imageView.setImageResource(R.drawable.qing);
            else if (tq.contains("阴"))
                holder.imageView.setImageResource(R.drawable.yin);
        }
        holder.textView.setText(temp[0]);
        holder.textView2.setText(temp[1]);
        holder.textView3.setText(temp[2]);
    }

    @Override
    public int getItemCount() {
        return dailyList.size();
    }
}
